import Mock from 'mockjs'
import type { Request } from 'express'
import { OutgoingHttpHeader } from 'http'
const {Random} = require('mockjs')

const OutpattientRecordsList = Mock.mock({
  'data|176':[
    {
      'id|+1': 0,
      'updateTime': '@datetime("y-MM-dd HH:mm:ss")',
      'orderId': /JF20([0,1][1-9]|2[0,3])(0[1-9]|1[0,1,2])([0,1,2][1-9]|3[0,1])\d{4}/,
      'name': '@cname',
      'department': '@pick(["儿科","外科","急诊科"])',
      'cardId': /\d{10}/,
      'source': '@pick(["微信小程序","支付宝","自助机","人工"])',
      'busType': '门诊缴费',
      'expenseType': '@pick(["医药费","检查费"])',
      'paidType': '@pick(["余额","现金"])',
      'paid': /\d{2,4}.\d{2}/,
      'status': '@pick(["已缴费","未缴费"])',
      'IDType': '身份证',
      'IDNumber': /\d{18}/,
      'wechatName': '@cword(2,6)',
      'tel': /1((34[0-8])|(8\d{2})|(([35][0-35-9]|4[579]|66|7[35678]|9[1389])\d{1}))\d{7}$/,
      'address': '北京市@pick(["海淀区","朝阳区","昌平区","房山区","大兴区"])@cword(2)路'+/\d{3}/+'号@cword(3,4)小区',
      'hospital': '北京市第一人民医院',
      'hospitalAddress': '北京市大兴区**路990号',
      'doctor': '@cname',
      'level': '@pick(["主任医师","副主任医师","专家"])',
      'recordList|4-6': [{
        'id|+1': 0,
        'name': '@pick(["普罗胶囊","阿司匹林肠溶片","地奈德乳膏","红霉素软膏"])',
        'price': /\d{2}.\d{2}/,
        'num': /\d/,
      }]
    }
  ]
})

//门诊消费列表
type outpatientRecordsQuery = {
  page?: number,
  pageSize?: number,
  startTime?: string,
  endTime?: string,
  department?: string,
  name?: string,
  card?: string,
  id?: number
}
const getOutpattientRecordsList = (req: Request) => {
  const {page=1,pageSize=10,startTime,endTime,department,name,card,id}: outpatientRecordsQuery = req.query
  const start = (page - 1) * pageSize
  const end = page * pageSize
  let defaultData = OutpattientRecordsList.data
  if(startTime && endTime) {
    defaultData = defaultData.filter(item => item.updateTime >= startTime && item.updateTime <= endTime)
  }
  if(department){
    defaultData = defaultData.filter(item => item.department === department)
  }
  if(name){
    defaultData = defaultData.filter(item => item.name === name)
  }
  if(card){
    defaultData = defaultData.filter(item => item.cardId === card)
  }
  if(id){
    defaultData = defaultData.filter(item => item.id ===id)
  }
  defaultData = defaultData.slice(start,end)

  return defaultData
}


export default [
    //获取门诊消费列表
    {
        methods: 'get',
        url: '/api/expenseManage/outpatientRecords',
        response: (req: Request) => ({
            code: 0,
            msk: 'ok',
            data: {
              list: getOutpattientRecordsList(req),
              total: OutpattientRecordsList.length,
              map: {
                ...req.query
              }
            }
        })
    },
    

]